namespace Xsxiaosa.Net
{
    using System;

    public class FtpResponse
    {
        // Methods
        internal FtpResponse()
        {
        }

        public FtpResponse(int code, string description, string raw)
        {
            if ((code < 100) || (code >= 600))
            {
                throw new ArgumentOutOfRangeException("code");
            }
            this._code = code;
            this._description = description;
            this._raw = raw;
        }

        internal FtpResponse Clone()
        {
            return new FtpResponse(this._code, this._description, this._raw);
        }

        internal void Reset()
        {
            this._code = 0;
            this._description = null;
            this._raw = null;
        }

        internal void SetMessage(string firstLine, int endOfLine)
        {
            try
            {
                this._code = int.Parse(firstLine.Substring(0, 3));
                this._description = firstLine.Substring(4, (endOfLine - 4)).Trim();
                this._raw = null;
            }
            catch
            {
                throw new FtpException(Xsxiaosa.Net.Messages.GetString(typeof(FtpStrings), "InvalidResponseCode"), FtpExceptionStatus.ServerProtocolViolation);
            }
            if ((this._code >= 100) && (this._code < 600))
            {
                return;
            }
            throw new FtpException(Xsxiaosa.Net.Messages.GetString(typeof(FtpStrings), "InvalidResponse"), FtpExceptionStatus.ServerProtocolViolation);
        }

        internal void SetRaw(string raw, int offset)
        {
            this._description = raw.Substring((offset + 4), ((raw.Length - offset) - 6));
            this._raw = raw;
        }


        // Properties
        public int Code
        {
            get
            {
                return this._code;
            }
        }

        public string Description
        {
            get
            {
                return this._description;
            }
        }

        public int Group
        {
            get
            {
                return (this._code / 100);
            }
        }

        public string Raw
        {
            get
            {
                object[] objArray1;
                if (this._raw == null)
                {
                    objArray1 = new object[4];
                    objArray1[0] = this._code;
                    objArray1[1] = " ";
                    objArray1[2] = this._description;
                    objArray1[3] = "\r\n";
                    this._raw = string.Concat(objArray1);
                }
                return this._raw;
            }
        }


        // Fields
        private int _code;
        private string _description;
        private string _raw;
    }}

